package com.sea.base.utils

import android.database.Observable
import androidx.lifecycle.Observer

/**
 * Author: Wu Chang
 * 全局的网络监听
 * Date: 2023/12/21 15:08
 */
object NetConnObs : Observable<Observer<Boolean>>() {

    @JvmStatic
    fun register(observer: Observer<Boolean>?) {
        if (observer == null || mObservers.contains(observer)) return
        super.registerObserver(observer)
    }

    @JvmStatic
    fun unregister(observer: Observer<Boolean>?) {
        if (observer == null || !mObservers.contains(observer)) return
        super.unregisterObserver(observer)
    }

    @JvmStatic
    fun sendChange(connect: Boolean) {
        synchronized(mObservers) {
            if (mObservers.isEmpty()) return
            mObservers.forEach { it.onChanged(connect) }
        }
    }
}